home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / wstype / source / beep.c < prev    next >
C/C++ Source or Header  |  1991-10-18  |  15KB  |  681 lines

  1. /***   [beep.c]
  2. *
  3. *    警告音 関連        (C)ささがわ
  4. *
  5. *    For GNU C Compiler (GCC)   Version 1.39
  6. *
  7. ***/
  8.  
  9. #include <io.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <dos.h>
  14. #include <jstring.h>
  15. #include "graph.h"
  16. #include "mos.h"
  17. #include "window.h"
  18. #include "beep.h"
  19. #include "others.h"
  20. #include "icn.h"
  21. #include "optparse.h"
  22.  
  23. #define WH_OTHER    0
  24. #define WH_OCTM        1
  25. #define WH_OCTP        10
  26. #define WH_KEY        2
  27. #define WH_VOLM        3
  28. #define WH_VOLP        11
  29. #define WH_VOL        12
  30. #define WH_FILE        4
  31. #define WH_EPCM        5
  32. #define WH_EBEEP    6
  33. #define WH_ENULL    7
  34. #define WH_CAN        8
  35. #define WH_TITLE    9
  36.  
  37. struct Par {
  38.     void    *data;
  39.     long    size;
  40.     char    name[20];
  41.     short    oct, ontei, onryo;
  42. };
  43.  
  44. extern int    PAL_Black, PAL_Button;
  45. static int    wx, wy;
  46. static int    Mode, Pcm;
  47. static struct Par    Main, Sub;
  48.  
  49. static void    Move(int, int);
  50. static void    Draw_window(void);
  51. static int    Where(int, int);
  52. static void Set_name(const unsigned char *, char *);
  53. static int    SUB_file(void);
  54. static void    errord(void);
  55. static void    Draw_oct(void);
  56. static void    Draw_ontei(void);
  57. static void    Draw_onryo(void);
  58. static void    SUB_key(int, int);
  59. static int    Where_key(int, int);
  60. static void    Draw_mes(int);
  61. static void    SUB_oct(int);
  62. static int    SUB_oct_sub(int);
  63. static void    Draw_volbar(void);
  64. static void SUB_vol(int);
  65. static int    SUB_vol_sub(int);
  66. static void    SUB_voldr(int, int);
  67. static int    Where_vol(int, int);
  68. static void    pcm_enable(void);
  69. static int    Settings(struct Par *, char *);
  70.  
  71. int BEP_init(void) {
  72.     int        r = 0;
  73.     char    path[90];
  74.     
  75.     if ((Mode = OPT_WarnS(path)) != 1)
  76.         return 0;
  77.     
  78.     ICN_mos(1);
  79.     Set_name((unsigned char *)path, Main.name);
  80.     if (Settings(&Main, path)) {
  81.         r = 1;
  82.         Mode = 0;
  83.         WIND_error(4, path);
  84.     }
  85.     ICN_mos(0);
  86.     
  87.     return r;
  88. }
  89.  
  90. void BEP_on(void) {
  91.     union REGS        regs;
  92.     struct SREGS    sregs;
  93.     
  94.     switch (Mode) {
  95.         case 1:
  96.             if (SND_pcm_status(71))
  97.                 SND_pcm_play_stop(71);
  98.             SND_pcm_play(71, Main.ontei, Main.onryo, Main.data);
  99.             break;
  100.         
  101.         case 2:
  102.             regs.h.ah = 0x02;
  103.             int86x(0x9e, ®s, ®s, &sregs);
  104.             break;
  105.         
  106.         default:
  107.             break;
  108.     }
  109. }
  110.  
  111. int WIND_beep(void) {
  112.     int        ret = 0;
  113.     struct RECT    a, b;
  114.     
  115.     wx = 151;
  116.     wy = 122;
  117.     a.x1 = 319;    a.y1 = 259;
  118.     a.x2 = 320;    a.y2 = 260;
  119.     b.x1 = wx;    b.y1 = wy;
  120.     b.x2 = wx + 337;    b.y2 = wy + 236;
  121.     afterImage(&a, &b);
  122.     
  123.     if (Mode == 1) {
  124.         Pcm = 1;
  125.         Sub = Main;
  126.         if ((Sub.data = malloc(Sub.size)) == NULL) {
  127.             WIND_error(1, NULL);
  128.             return -1;
  129.         }
  130.         memcpy(Sub.data, Main.data, Sub.size);
  131.     } else {
  132.         Pcm = 0;
  133.         Sub.oct = 4;
  134.         Sub.ontei = 60;
  135.         Sub.onryo = 127;
  136.         Sub.name[0] = '\0';
  137.     }
  138.     
  139.     Draw_window();
  140.     while (!ret) {
  141.         char    mb;
  142.         int        mx, my;
  143.         
  144.         CLOCK(0);
  145.         if (MOS_rdpos(&mb, &mx, &my), !(mb & 1))
  146.             continue;
  147.         
  148.         switch (Where(mx, my)) {
  149.             case WH_CAN:
  150.                 if (Button(wx + 6, wy + 6, wx + 25, wy + 25))
  151.                     ret = 2;
  152.                 break;
  153.             case WH_FILE:
  154.                 if (Button(wx + 195, wy + 138, wx + 308, wy + 155)) {
  155.                     if (SUB_file()) {
  156.                         Mode = 0;
  157.                         ret = -1;
  158.                     }
  159.                 }
  160.                 break;
  161.             case WH_KEY:    SUB_key(mx, my);    break;
  162.             case WH_OCTM:    SUB_oct(1);        break;
  163.             case WH_OCTP:    SUB_oct(0);        break;
  164.             case WH_VOLM:    SUB_vol(1);        break;
  165.             case WH_VOLP:    SUB_vol(0);        break;
  166.             case WH_VOL:    SUB_voldr(mx, my);    break;
  167.             case WH_EPCM:
  168.                 if (!Pcm)    break;
  169.                 if (Button(wx + 25, wy + 198, wx + 102, wy + 219)) {
  170.                     void    *p;
  171.                     
  172.                     p = Main.data;
  173.                     Main = Sub;
  174.                     Sub.data = p;
  175.                     Mode = 1;
  176.                     ret = 1;
  177.                 }
  178.                 break;
  179.             case WH_EBEEP:
  180.                 if (Button(wx + 130, wy + 198, wx + 207, wy + 219)) {
  181.                     free(Main.data);
  182.                     Main.data = NULL;
  183.                     Mode = 2;
  184.                     ret = 1;
  185.                 }
  186.                 break;
  187.             case WH_ENULL:
  188.                 if (Button(wx + 235, wy + 198, wx + 312, wy + 219)) {
  189.                     free(Main.data);
  190.                     Main.data = NULL;
  191.                     Mode = 0;
  192.                     ret = 1;
  193.                 }
  194.                 break;
  195.             case WH_TITLE:    Move(mx, my);    break;
  196.             default:    while (MOS_rdpos(&mb, &mx, &my), mb & 1);    break;
  197.         }
  198.     }
  199.     free(Sub.data);
  200.     Sub.data = NULL;
  201.     
  202.     return (ret < 0 ? -1 : 0);
  203. }
  204.  
  205. static void Move(int mx, int my) {
  206.     struct RECT    s, w;
  207.     
  208.     w.x1 = wx;    w.y1 = wy;
  209.     w.x2 = wx + 337;    w.y2 = wy + 236;
  210.     s.x1 = 0;    s.y1 = 40;    s.x2 = 639;    s.y2 = 463;
  211.     if (dragWindow(mx, my, &w, &s, 0, 0)) {
  212.         wx = w.x1;    wy = w.y1;
  213.         MOS_disp(0);
  214.         EGB_cls(0);
  215.         MOS_disp(1);
  216.         Draw_window();
  217.     }
  218. }
  219.  
  220. static void Draw_window(void) {
  221.     int        i, c;
  222.     struct opnwin_t    opw;
  223.     
  224.     opw.title = "警  告  音";
  225.     opw.x1 = wx;
  226.     opw.y1 = wy;
  227.     opw.x2 = opw.x1 + 337;
  228.     opw.y2 = opw.y1 + 236;
  229.     opw.shdw = 1;
  230.     opw.canb = 1;
  231.     opw.nopt = 0;
  232.     opw.wopt = NULL;
  233.     opw.expb = 0;
  234.     opw.ord = 0;
  235.     MOS_disp(0);
  236.     drawWindow(&opw);
  237.     
  238.     EGB_str2("オクターブ", wx + 14, wy + 54, PAL_Black);
  239.     DrawButton(1, wx + 102, wy + 37, wx + 121, wy + 56);
  240.     EGB_box(wx + 121, wy + 37, wx + 140, wy + 56, PAL_Black);
  241.     DrawButton(1, wx + 140, wy + 37, wx + 159, wy + 56);
  242.     EGB_boxf(wx + 107, wy + 46, wx + 116, wy + 47, PAL_Black, PAL_Black);    /* - */
  243.     EGB_boxf(wx + 145, wy + 46, wx + 154, wy + 47, PAL_Black, PAL_Black);    /* + */
  244.     EGB_boxf(wx + 149, wy + 42, wx + 150, wy + 51, PAL_Black, PAL_Black);
  245.     Draw_oct();
  246.     
  247.     for (i = 0; i < 7; i++)
  248.         EGB_boxf(wx + i * 19 + 20, wy + 67, wx + i * 19 + 39, wy + 156, PAL_Black, 15);
  249.     for (i = 0; i < 2; i++)
  250.         EGB_boxf(wx + i * 21 + 31, wy + 67, wx + i * 21 + 45, wy + 116, PAL_Black, 8);
  251.     for (i = 0; i < 3; i++)
  252.         EGB_boxf(wx + i * 21 + 87, wy + 67, wx + i * 21 + 101, wy + 116, PAL_Black, 8);
  253.     
  254.     EGB_str2("音程 No.", wx + 180, wy + 54, PAL_Black);
  255.     Draw_ontei();
  256.     EGB_str2("音量", wx + 180, wy + 74, PAL_Black);
  257.     Draw_onryo();
  258.     
  259.     EGB_str2("音量", wx + 180, wy + 104, PAL_Black);
  260.     DrawButton(1, wx + 220, wy + 89, wx + 236, wy + 105);
  261.     EGB_boxf(wx + 236, wy + 89, wx + 307, wy + 105, PAL_Black, 6);
  262.     DrawButton(1, wx + 307, wy + 89, wx + 323, wy + 105);
  263.     EGB_line(wx + 224, wy + 97, wx + 232, wy + 97, PAL_Black);    /* - */
  264.     EGB_line(wx + 311, wy + 97, wx + 319, wy + 97, PAL_Black);    /* + */
  265.     EGB_line(wx + 315, wy + 93, wx + 315, wy + 101, PAL_Black);
  266.     Draw_volbar();
  267.     
  268.     EGB_str2("サウンドファイル名", wx + 180, wy + 134, PAL_Black);
  269.     EGB_box(wx + 194, wy + 137, wx + 309, wy + 156, PAL_Black);
  270.     EGB_str2(Sub.name, wx + 204, wy + 154, PAL_Black);
  271.     
  272.     c = Pcm ? PAL_Black : 7;
  273.     DrawButton(1, wx + 24, wy + 197, wx + 103, wy + 220);
  274.     for (i = 0; i < 2; i++)
  275.         EGB_str2("P C M", wx + 32 + i, wy + 216, c);
  276.     DrawButton(1, wx + 129, wy + 197, wx + 208, wy + 220);
  277.     for (i = 0; i < 2; i++)
  278.         EGB_str2("BEEP", wx + 137 + i, wy + 216, PAL_Black);
  279.     DrawButton(1, wx + 234, wy + 197, wx + 313, wy + 220);
  280.     for (i = 0; i < 2; i++)
  281.         EGB_str2(" な  し ", wx + 242 + i, wy + 216, PAL_Black);
  282.     
  283.     MOS_disp(1);
  284.     Draw_mes(0);
  285. }
  286.  
  287. static int Where(int x, int y) {
  288.     int        i, ret = WH_OTHER;
  289.     static const short    tab[][5] = {
  290.         { 102, 121, 37, 56, WH_OCTM},    { 140, 159, 37, 56, WH_OCTP},
  291.         { 20, 153, 67, 156, WH_KEY},    { 220, 236, 89, 105, WH_VOLM},
  292.         { 236, 307, 89, 105, WH_VOL},    { 307, 323, 89, 105, WH_VOLP},
  293.         { 194, 309, 137, 156, WH_FILE},    { 24, 103, 197, 220, WH_EPCM},
  294.         { 129, 208, 197, 220, WH_EBEEP},{ 234, 313, 197, 220, WH_ENULL},
  295.         { 5, 26, 5, 26, WH_CAN},        { 26, 332, 5, 26, WH_TITLE}
  296.     };
  297.     
  298.     x -= wx;
  299.     y -= wy;
  300.     for (i = 0; i < 12; i++) {
  301.         const short    *p = tab[i];
  302.         
  303.         if (p[0] < x && x < p[1] && p[2] < y && y < p[3]) {
  304.             ret = p[4];
  305.             break;
  306.         }
  307.     }
  308.     
  309.     return ret;
  310. }
  311.  
  312. static void Set_name(const unsigned char *str, char *buf) {        /* ニホンゴ タイオウ */
  313.     int        i;
  314.     unsigned char    a[100], *p;
  315.     
  316.     strcpy((char *)a, (const char *)str);
  317.     p = a;
  318.     while ((p = jstrchr(p, '\\')) != NULL)    *(p++) = '\x01b';
  319.     
  320.     for (i = strlen((char *)a) - 1; i > 0; i--) {
  321.         if (a[i - 1] == '\x01b' || a[i - 1] == ':')
  322.             break;
  323.     }
  324.     
  325.     if (strlen((char *)a + i) > 12) {
  326.         buf[0] = '\0';
  327.         strncat(buf, (char *)a + i, strLE((char *)a + i, 12));
  328.     } else
  329.         strcpy(buf, (char *)a + i);
  330.     strlow(1, (unsigned char *)buf);
  331. }
  332.  
  333. static int SUB_file(void) {
  334.     int        ret, res;
  335.     char    path[85];
  336.     
  337.     MOS_disp(0);
  338.     EGB_cls(0);
  339.     MOS_disp(1);
  340.     res = WIND_filesel("サウンドファイル", path);
  341.     MOS_disp(0);
  342.     EGB_cls(0);
  343.     MOS_disp(1);
  344.     
  345.     switch (res) {
  346.         case 1:
  347.             ret = 0;
  348.             if (SND_pcm_status(71))
  349.                 SND_pcm_play_stop(71);
  350.             Set_name((unsigned char *)path, Sub.name);
  351.             Draw_window();
  352.             ICN_mos(1);
  353.             if (Settings(&Sub, path)) {
  354.                 ICN_mos(0);
  355.                 errord();
  356.                 break;
  357.             }
  358.             MOS_disp(0);
  359.             Draw_oct();
  360.             Draw_ontei();
  361.             MOS_disp(1);
  362.             pcm_enable();
  363.             ICN_mos(0);
  364.             break;
  365.         case -1:    ret = -1;    break;
  366.         default:
  367.             Draw_window();
  368.             ret = 0;
  369.             break;
  370.     }
  371.     
  372.     return ret;
  373. }
  374.  
  375. static void errord(void) {
  376.     int        i;
  377.     
  378.     Draw_mes(1);
  379.     MOS_disp(0);
  380.     for (i = 0; i < 2; i++)
  381.         EGB_str2("P C M", wx + 32 + i, wy + 216, 7);
  382.     MOS_disp(1);
  383.     Pcm = 0;
  384.     return;
  385. }
  386.  
  387. static void pcm_enable(void) {
  388.     int        i;
  389.     
  390.     Draw_mes(0);
  391.     MOS_disp(0);
  392.     for (i = 0; i < 2; i++)
  393.         EGB_str2("P C M", wx + 32 + i, wy + 216, PAL_Black);
  394.     MOS_disp(1);
  395.     Pcm = 1;
  396.     return;
  397. }
  398.  
  399. static void Draw_oct(void) {
  400.     unsigned char    buf[5];
  401.     unsigned short    code;
  402.     
  403.     code = Sub.oct + 0x824f;
  404.     buf[0] = (code >> 8) & 0xff;
  405.     buf[1] = code & 0xff;
  406.     buf[2] = '\0';
  407.     EGB_str3((char *)buf, wx + 123, wy + 54, PAL_Black, 7);
  408. }
  409.  
  410. static void Draw_ontei(void) {
  411.     char    buf[5];
  412.     
  413.     sprintf(buf, "%3d", Sub.ontei);
  414.     EGB_str3(buf, wx + 252, wy + 54, PAL_Black, 7);
  415. }
  416.  
  417. static void Draw_onryo(void) {
  418.     char    buf[5];
  419.     
  420.     sprintf(buf, "%3d", Sub.onryo);
  421.     EGB_str3(buf, wx + 252, wy + 74, PAL_Black, 7);
  422. }
  423.  
  424. static void Draw_volbar(void) {
  425.     int        i;
  426.     
  427.     i = wx + Sub.onryo * 55 / 127 + 244;
  428.     if (i - 7 > wx + 237)
  429.         EGB_boxf(wx + 237, wy + 90, i - 8, wy + 104, 6, 6);
  430.     DrawButton(0, i - 7, wy + 90, i + 7, wy + 104);
  431.     if (i + 7 < wx + 306)
  432.         EGB_boxf(i + 8, wy + 90, wx + 306, wy + 104, 6, 6);
  433. }
  434.  
  435. static void SUB_key(int x, int y) {
  436.     int        wh, d, fl;
  437.     char    mb;
  438.     
  439.     if (!Pcm)    return;
  440.     ICN_mos(2);
  441.     wh = Where_key(x, y);
  442.     Sub.ontei = (Sub.oct - 1) * 12 + 24 + wh;
  443.     Draw_ontei();
  444.     if (SND_pcm_mode_set(71))
  445.         SND_pcm_play_stop(71);
  446.     switch (SND_pcm_play(71, Sub.ontei, Sub.onryo, Sub.data)) {
  447.         case 6:
  448.         case 8:
  449.         case 9:        Draw_mes(2);    break;
  450.         case 11:    Draw_mes(3);    break;
  451.         default:    Draw_mes(0);    break;
  452.     }
  453.     fl = 1;
  454.     while (MOS_rdpos(&mb, &d, &d), mb & 1) {
  455.         if (fl && !SND_pcm_status(71)) {
  456.             ICN_mos(0);
  457.             fl = 0;
  458.         }
  459.     }
  460.     ICN_mos(0);
  461. }
  462.  
  463. static int Where_key(int x, int y) {
  464.     int        i;
  465.     
  466.     x -= (wx + 20);
  467.     y -= (wy + 67);
  468.     
  469.     for (i = 0; i < 2; i++) {
  470.         if (i * 21 + 11 < x && x < i * 21 + 25 && 0 < y && y < 49)
  471.             return (i * 2 + 1);
  472.     }
  473.     for (i = 0; i < 3; i++) {
  474.         if (i * 21 + 67 < x && x < i * 21 + 81 && 0 < y && y < 49)
  475.             return (i * 2 + 6);
  476.     }
  477.     for (i = 0; i < 3; i++) {
  478.         if (i * 19 < x && x < (i + 1) * 19 && 0 < y && y < 89)
  479.             return (i * 2);
  480.     }
  481.     for (i = 0; i < 4; i++) {
  482.         if (i * 19 + 57 < x && x < (i + 1) * 19 + 57 && 0 < y && y < 89)
  483.             return (i * 2 + 5);
  484.     }
  485.     
  486.     return -1;
  487. }
  488.  
  489. static void Draw_mes(int no) {
  490.     int        i;
  491.     static const char    mes[][38] = {
  492.         "上記の設定は、PCMでのみ有効です",
  493.         "サウンドの読み込みに失敗しました",
  494.         "サウンドデータに異常があります",
  495.     };
  496.     
  497.     if (no < 0 || 2 < no)
  498.         return;
  499.     i = wx + 6 + (326 - strlen(mes[no]) * 8) / 2;
  500.     
  501.     MOS_disp(0);
  502.     EGB_boxf(wx + 6, wy + 167, i - 1, wy + 186, 7, 7);
  503.     EGB_str3(mes[no], i, wy + 184, PAL_Black, 7);
  504.     EGB_boxf(i + strlen(mes[no]) * 8, wy + 167, wx + 331, wy + 186, 7, 7);
  505.     MOS_disp(1);
  506. }
  507.  
  508. static void SUB_oct(int m) {
  509.     int        flpush = 1, fllast;
  510.     int        mx, my, lx, ly;
  511.     char    mb;
  512.     
  513.     lx = wx + (m ? 103 : 141);
  514.     ly = wy + 38;
  515.     
  516.     EGB_rev(1, lx, ly, lx + 17, ly + 17);
  517.     fllast = SUB_oct_sub(m);
  518.     TIMER_set(20);
  519.     
  520.     while (MOS_rdpos(&mb, &mx, &my), mb & 1) {
  521.         int        whres;
  522.         
  523.         whres = Where(mx, my) == (m ? WH_OCTM : WH_OCTP);
  524.         if (!whres && flpush || whres && !flpush) {
  525.             EGB_rev(1, lx, ly, lx + 17, ly + 17);
  526.             flpush = !flpush;
  527.         }
  528.         
  529.         if (flpush && TIMER() && !fllast) {
  530.             fllast = SUB_oct_sub(m);
  531.             TIMER_set(20);
  532.         }
  533.     }
  534.     
  535.     if (flpush)
  536.         EGB_rev(1, lx, ly, lx + 17, ly + 17);
  537. }
  538.  
  539. static int SUB_oct_sub(int m) {
  540.     int        result = 1;
  541.     
  542.     if (m && Sub.oct > 1 || !m && Sub.oct < 8) {
  543.         m ? Sub.oct-- : Sub.oct++;
  544.         MOS_disp(0);
  545.         Draw_oct();
  546.         MOS_disp(1);
  547.         result = 0;
  548.     }
  549.     
  550.     return result;
  551. }
  552.  
  553. static void SUB_vol(int m) {
  554.     int        flpush = 1, fllast, lx, ly;
  555.     int        mx, my;
  556.     char    mb;
  557.     
  558.     lx = wx + (m ? 221 : 308);
  559.     ly = wy + 90;
  560.     
  561.     EGB_rev(1, lx, ly, lx + 14, ly + 14);
  562.     fllast = SUB_vol_sub(m);
  563.     TIMER_set(20);
  564.     
  565.     while (MOS_rdpos(&mb, &mx, &my), mb & 1) {
  566.         int        whres;
  567.         
  568.         whres = Where(mx, my) == (m ? WH_VOLM : WH_VOLP);
  569.         if (!whres && flpush || whres && !flpush) {
  570.             EGB_rev(1, lx, ly, lx + 14, ly + 14);
  571.             flpush = !flpush;
  572.         }
  573.         
  574.         if (flpush && TIMER() && !fllast)
  575.             fllast = SUB_vol_sub(m);
  576.     }
  577.     
  578.     if (flpush)
  579.         EGB_rev(1, lx, ly, lx + 14, ly + 14);
  580. }
  581.  
  582. static int SUB_vol_sub(int m) {
  583.     int        result = 1;
  584.     
  585.     if (m && Sub.onryo > 0 || !m && Sub.onryo < 127) {
  586.         m ? Sub.onryo-- : Sub.onryo++;
  587.         MOS_disp(0);
  588.         Draw_volbar();
  589.         Draw_onryo();
  590.         MOS_disp(1);
  591.         result = 0;
  592.     }
  593.     
  594.     return result;
  595. }
  596.  
  597. static void SUB_voldr(int x, int y) {
  598.     int        wh;
  599.     char    mb;
  600.     
  601.     if ((wh = Where_vol(x, y)) < 0)
  602.         return;
  603.     
  604.     ICN_mos(3);
  605.     Sub.onryo = wh * 127 / 55;
  606.     MOS_disp(0);
  607.     Draw_volbar();
  608.     Draw_onryo();
  609.     MOS_disp(1);
  610.     
  611.     while (MOS_rdpos(&mb, &x, &y), mb & 1) {
  612.         if ((wh = Where_vol(x, y)) < 0)
  613.             continue;
  614.         
  615.         wh = wh * 127 / 55;        /* NOT wh *= 127 / 55 */
  616.         if (wh != Sub.onryo) {
  617.             wh < Sub.onryo ? Sub.onryo-- : Sub.onryo++;
  618.             MOS_disp(0);
  619.             Draw_volbar();
  620.             Draw_onryo();
  621.             MOS_disp(1);
  622.         }
  623.     }
  624.     ICN_mos(0);
  625. }
  626.  
  627. static int Where_vol(int x, int y) {
  628.     int        ret;
  629.     
  630.     if (Where(x, y) != WH_VOL) {
  631.         ret = -1;
  632.     } else {
  633.         ret = x - (wx + 244);
  634.         if (ret < 0)
  635.             ret = 0;
  636.         else if (ret > 55)
  637.             ret = 55;
  638.     }
  639.     
  640.     return ret;
  641. }
  642.  
  643. static int Settings(struct Par *p, char *path) {
  644.     FILE    *fp;
  645.     
  646.     free(p->data);
  647.     p->data = NULL;
  648.     if ((fp = fopen(path, "rb")) == NULL)
  649.         return 1;
  650.     if ((p->size = filelength(fileno(fp))) <= 32) {
  651.         fclose(fp);
  652.         return 2;
  653.     }
  654.     if ((p->data = malloc(p->size)) == NULL) {
  655.         fclose(fp);
  656.         return 3;
  657.     }
  658.     clearerr(fp);
  659.     fread(p->data, 1, p->size, fp);
  660.     if (ferror(fp) || feof(fp)) {
  661.         fclose(fp);
  662.         free(p->data);
  663.         p->data = NULL;
  664.         return 1;
  665.     }
  666.     if (p->size < *((unsigned long *)((char *)p->data + 12)) + 32) {
  667.         fclose(fp);
  668.         free(p->data);
  669.         p->data = NULL;
  670.         return 2;
  671.     }
  672.     fclose(fp);
  673.     
  674.     p->ontei = *((unsigned char *)p->data + 28);
  675.     if (p->ontei < 24 || 119 < p->ontei)    p->ontei = 60;
  676.     p->oct = (p->ontei - 24) / 12 + 1;
  677.     p->onryo = 127;
  678.     
  679.     return 0;
  680. }
  681.